<template>
  <share v-model="value"
         :keyName="keyName"
         :keyShow="keyShow"
         :size="size"
         :svc="svc()"
         :urlPage="urlPage"
         :urlIds="urlIds"
         :isMultiple="isMultiple"
         :isBtn="isBtn"
         :style="style"
         :title="title"
         :disabled="disabled"
         :params="params"
         :placeholder="placeholder">
    <template v-slot:selectItem="{item}">
      {{ `${item['organizationCode'] || ''}-${item['organizationName'] || ''}` }}
    </template>
    <template v-slot:queryFrom="{listQuery,handleFilter}">
      <el-form-item prop="organizationCode" label="部门编码">
        <el-input v-model="listQuery['organizationCode']" placeholder="部门编码" @keyup.enter="handleFilter"/>
      </el-form-item>
      <el-form-item prop="organizationName" label="部门名称">
        <el-input v-model="listQuery['organizationName']" placeholder="部门名称" @keyup.enter="handleFilter"/>
      </el-form-item>
      <el-form-item prop="state" label="状态">
        <el-radio-group v-model="listQuery['state']" disabled>
          <el-radio-button label="" key="">全部</el-radio-button>
          <el-radio-button v-for="(item,index) in getEnumList('CommonEnableDisable')" :label="item.key" :key="index">{{item.value}}</el-radio-button>
        </el-radio-group>
      </el-form-item>
    </template>
    <template #queryTable>
      <el-table-column align="center" prop="organizationType" label="部门类型">
        <template v-slot="{row}">
          <EnumTag :enum-list="getEnumList('OrganizationType')" :enum-key="row.organizationType" />
        </template>
      </el-table-column>
      <el-table-column align="center" prop="organizationCode" label="部门编码" />
      <el-table-column align="center" prop="organizationName" label="部门名称" />
      <el-table-column align="center" prop="state" label="状态">
        <template v-slot="{row}">
          <EnumTag :enum-list="getEnumList('CommonEnableDisable')" :enum-key="row.state" />
        </template>
      </el-table-column>
    </template>
  </share>
</template>

<script>
import share from "@/views/components";
import {commonEnableDisables, getEnumList, svc} from "@/config/common";

export default {
  name: "selectOrganization",
  components: {share},
  emits: ['update:modelValue'],
  props: {
    placeholder: {
      type: String,
      default: ''
    },
    modelValue: {
      type: String
    },
    isBtn: {
      type: Boolean,
      default: false
    },
    keyName: 'id',
    keyShow: 'organizationName',
    isMultiple: {
      type: Boolean,
      default: false
    },
    size: {
      default: 'default'
    },
    style: {
      default: ''
    },
    title: {
      type: String
    },
    params: {
      type: Object,
      default: () => ({state: commonEnableDisables().enabled})
    },
    disabled: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      value: '',
      urlPage: '/organization/page',
      urlIds: '/organization/ids',
    }
  },
  watch: {
    value() {
      this.$emit('update:modelValue', this.value)
    },
    modelValue(val) {
      this.value = val
    }
  },
  created() {
    this.value = this.modelValue
  },
  methods: {
    getEnumList,
    svc() {
      return svc
    },
  }
}
</script>
<style scoped lang="scss">
</style>
